/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;


import java.sql.PreparedStatement;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import model.Release;

/**
 *
 * @author Adriano
 */
public class ReleaseDAO implements DAO {

	final static Logger logger = LogManager.getLogger(ReleaseDAO.class);
	
    private final DataSource dataSource;

    public ReleaseDAO() {
        dataSource = new DataSource();
    }

    public void create(Object o) {
        try {

            String sql = "INSERT INTO releases VALUES (null,?,?,?,?,?,?)";
            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);

            Release lancamento = (Release) o;

            
            ps.setString(1, lancamento.getLstNatureza());
            ps.setString(2, lancamento.getTxtConta());
            ps.setString(3, lancamento.getTxtValor());
            ps.setString(4, lancamento.getLstHistorico());
            ps.setString(5, lancamento.getTxtComplementoHistorico());
            ps.setString(6, lancamento.getTxtdate());
           
            
            int res = ps.executeUpdate();
            ps.close();
            
            if (res == 0) {
                logger.info("Nenhum lancamento registrado !");

            }

        } catch (Exception e) {
        	System.out.println(e.getMessage());
             logger.error("LANCAMENTODAO.CREATE " , e);

        }
    }

    public void delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }

    public void update(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }

    public Object read(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }
    
    
     public void closeDAO() {
        dataSource.closeConnection();
    }

}
